package com.jz.community.moduleshopping.orderList.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.confirmOrder.payPop.NewCommPayPopUp;
import com.jz.community.moduleshopping.orderList.bean.NewOrderListInfo;

import java.util.List;

/**
 * Created by Tony.Fan on 2018/4/27 10:18
 * 多个商品
 */
public class OrderMultiGoodsAdapter extends BaseQuickAdapter<NewOrderListInfo.EmbeddedBean.OrderInfoesBean.OrderItemListBean, BaseViewHolder> {

    private int count = 0;

    public OrderMultiGoodsAdapter(@Nullable List datas) {
        super(R.layout.order_multi_goods, datas);
    }

    @Override
    protected void convert(BaseViewHolder helper, NewOrderListInfo.EmbeddedBean.OrderInfoesBean.OrderItemListBean orderItem) {
        LinearLayout order_multi_num_ll = helper.getView(R.id.order_multi_num_ll);
        TextView order_multi_num = helper.getView(R.id.order_multi_num);
        BaseImageLoaderUtils.getInstance().loadDefaltImage(mContext, helper.getView(R.id.order_multi_iv), orderItem.getGoodsImg());
        goodsCount(orderItem);
        if ((getItemCount() - 1) == helper.getAdapterPosition()) {
            SHelper.vis(order_multi_num_ll);
            order_multi_num.setText(count + "件");
        } else {
            SHelper.gone(order_multi_num_ll);
        }
    }

    /**
     * 购买商品数量
     *
     * @param orderItem
     * @return
     */
    private int goodsCount(NewOrderListInfo.EmbeddedBean.OrderInfoesBean.OrderItemListBean orderItem) {
        if (!Preconditions.isNullOrEmpty(orderItem.getGoodsCount())) {
            count += orderItem.getGoodsCount();
        }
        return count;
    }
}
